//Documentation complete
/**
 * @author Jason Funk
 * @version 2009MR31
 */

package problemDomain;

import static problemDomain.ErrorBean.*;
import static problemDomain.ErrorBean.ErrorCode.*;
import static utilities.XMLTools.encodeEntities;

import java.util.ArrayList;
import java.util.List;

/**
 * Holds data for a sales per time period report.
 */
public class SalesPerTimePeriodReportBean implements Bean {
	
	/* Constants */
	
	private static final long serialVersionUID = 2534090064694892451L;
	
	/* END Constants */
	
	
	/* Attributes */
	
	private String title;
	private List<String> reportList;
	private String total;
	private String timePeriod;
	
	/* END Attributes */
	
	
	/* Constructors */
	
	/**
	 * Constructs a <code>SalesPerTimePeriodBean</code> with default values.
	 */
	public SalesPerTimePeriodReportBean () {
		title = "";
		reportList = new ArrayList<String>();
		total = "";
		timePeriod = "";
	}
	
	/**
	 * Constructs a <code>SalesPerTimePeriodBean</code> with specified values.
	 * @param reportList the report list
	 * @param total the report total
	 * @param timePeriod the time period of the report
	 */
	public SalesPerTimePeriodReportBean (List<String> reportList, String total, String timePeriod) {
		this.title = "SALES PER " + timePeriod.toUpperCase();
		this.reportList = reportList;
		this.total = total;
		this.timePeriod = timePeriod;
	}
	
	/* END Constructors */
	
	
	/* Accessors */
	
	/**
	 * Returns the title of the report.
	 * @return the title of the report
	 */
	public String getTitle () {
		return title;
	}

	/**
	 * Returns the report list.
	 * @return the report list
	 */
	public List<String> getReportList () {
		return reportList;
	}

	/**
	 * Returns the report total,
	 * @return the report total
	 */
	public String getTotal () {
		return total;
	}

	/**
	 * Returns the time period.
	 * @return the time period
	 */
	public String getTimePeriod () {
		return timePeriod;
	}
	
	/* END Accessors */
	
	
	/* Mutators */

	/**
	 * Sets the report title.
	 * @param title the report title
	 */
	public void setTitle (String title) {
		this.title = title;
	}

	/**
	 * Sets the report list.
	 * @param reportList the report list
	 */
	public void setReportList (List<String> reportList) {
		this.reportList = reportList;
	}

	/**
	 * Sets the report total.
	 * @param total the report total
	 */
	public void setTotal (String total) {
		this.total = total;
	}

	/**
	 * Sets the time period.
	 * @param timePeriod the time period
	 */
	public void setTimePeriod (String timePeriod) {
		this.timePeriod = timePeriod;
	}
	
	/* END Mutators */
	
	
	/* (Bean) Methods */
	
	@Override
	public boolean isValid () throws ErrorBean {
		if (reportList == null)
			throwError(
				REPORT_INVALID_REPORTLIST,
				this);
		if (total == null)
			throwError(
				REPORT_INVALID_TOTAL,
				this);
		return true;
	}

	@Override
	public String toXML () {
		StringBuilder sb = new StringBuilder();
		sb.append("<report>");
		sb.append("<title>" + title + "</title>");
		sb.append("<menuitems>");
		for (int i = 0; i < reportList.size(); i++)
			sb.append(reportList.get(i));
		sb.append("</menuitems>");
		sb.append("<reporttotal>" + total + "</reporttotal>");
		sb.append("<timeperiod>" + timePeriod + "</timeperiod>");
		sb.append("</report>");
		return encodeEntities(sb.toString());
	}
	
	/* END (Bean) Methods */
	
}
